package com.wsj.aop.customize;

import java.beans.PropertyEditorSupport;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 自定义日期编辑器
 *
 * @author yang
 * @date 2019/4/3 20:58
 */
public class DatePropertyEditor extends PropertyEditorSupport {

  private String format = "yyyy-MM-dd";

  public void setFormat(String format) {
    this.format = format;
  }

  @Override
  public void setAsText(String text) throws IllegalArgumentException {
    System.out.println("args:" + text);
    DateFormat dateFormat = new SimpleDateFormat(format);
    try {
      Date date = dateFormat.parse(text);
      this.setValue(date);
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
}
